# -*- coding: utf-8 -*-

'''
Created on 26/11/2011

@author: Luis M. Ugalde
www.forondarena.net

Copyright © 2011 Luis M. Ugalde
Licensed under the terms of the MIT License
(see LICENSE file for details)

This software can't be considered to be even in Alpha state. It still needs a lot of work.
'''


import sys
from writers.writerexception import WriterException


class Writer(object):
    '''
    Writer facade-like structural pattern.
    '''


    def __init__(self, writertype, availablewriters, *args, **kwargs):
        '''
        self.availableclasses = {'WriterFile': wtfile.WriterFile,
                        'WriterSolr': wtsolr.WriterSolr
                        }
        '''
                
        self.availableclasses = availablewriters
        
        try:
            module, klass = self.availableclasses[writertype].split(".")
            _tmpmodule = __import__(module, globals(), locals(), [], 1)
            self.writer = getattr(sys.modules['writers.' + module], klass)(*args, **kwargs)
        except TypeError:
            raise WriterException('AbstractWriter interface must be fully implemented')
        except KeyError:
            raise WriterException('Writer type is not valid')
        except ImportError:
            raise WriterException('Cant import required module')


    def setSource(self, *args, **kwargs):
        '''
        '''
        self.writer.setSource(*args, **kwargs)


    def connectSources(self, *args, **kwargs):
        '''
        '''
        self.writer.connectSources(*args, **kwargs)


    def setNotifySource(self, *args, **kwargs):
        '''
        '''
        self.writer.setNotifySource(*args, **kwargs)


    def connectNotifySources(self, *args, **kwargs):
        '''
        '''
        self.writer.connectNotifySources(*args, **kwargs)


    def setBindWriter(self, *args, **kwargs):
        '''
        '''
        self.writer.setBindWriter(*args, **kwargs)
        
        
    def bindWriter(self, *args, **kwargs):
        '''
        '''
        self.writer.bindWriter(*args, **kwargs)

    
    def putRecords(self, *args, **kwargs):
        '''
        '''
        self.writer.putRecords(*args, **kwargs)


if __name__ == '__main__':
    print "Please, do not run this"
